import { RawMessage, world } from "@minecraft/server";
import { setModId } from "./data/info";
import { setModName } from "./data/meta";
import { LoggerManager, setQuestNameSpace, utils } from "./index";

/**
 * Initialize the mod.
 * @param id Id of the mod.
 * @param metadata Metadata of the mod.
 * @param options Additional options for the mod.
 */
export function initializeMod(
  id: string,
  metadata: modMetadata,
  options?: modOptions,
) {
  setModId(id);
  setModName(metadata.name);
  if (options?.questNameSpace) {
    setQuestNameSpace(options.questNameSpace);
  }
  if (options?.watchdogDisabled) {
    utils.disabledWatchdog();
  }
  world.afterEvents.worldInitialize.subscribe((event) => {
    if (options?.events) options.events();
  });
}

/**
 * Additional options for the mod.
 */
export interface modOptions {
  /**
   * Metadata of the mod.
   */
  metadata: modMetadata;
  /**
   * Namespace of Quest Complete Tag.
   */
  questNameSpace?: string;
  /**
   * Disabled Watchdog.
   */
  watchdogDisabled?: boolean;
  /**
   * This event fires when the script environment is initialized on a world.
   */
  events?: () => void;
}

/**
 * Metadata of the mod.
 */
export interface modMetadata {
  /**
   * Name of the mod, default is `Minecraft`
   *
   * i18n is not supported.
   */
  name: string;
  /**
   * A short description of the mod.
   */
  description?: string | RawMessage;
}
